﻿/**
 * 应用程序源码文件
 */
#ifndef STT_HMIAPP_CPP_
#define STT_HMIAPP_CPP_

/*********************
 *   头文件
 *********************/
#include "HmiApp.h"
/*PAGES_HEAD_BEGIN*/
#include "pages/Frm01.h"
#include "pages/Frm02.h"
#include "pages/Frm03.h"
#include "pages/Frm04.h"
#include "pages/Frm05.h"
#include "pages/Frm06.h"
#include "pages/Frm07.h"
#include "pages/Frm08.h"
#include "pages/Frm09.h"
#include "pages/Frm10.h"
/*PAGES_HEAD_END*/

using namespace stt;

/********************************
 *
 *  应用程序入口
 *
 *  注意：IDE自动生成，用户勿修改
 *
 ********************************/
IApplication * AppMain(IRuntime* env, char **argv){
	return new HmiApp(env);
}

string getAppArgs() {
	return "{\"r\":0}";
}

/********************************
 *
 *  应用程序类
 *
 *  注意：用户可添加代码
 *
 ********************************/
HmiApp::HmiApp(IRuntime * rt) : HmiAppBase(rt) {
}

HmiApp::~HmiApp() {
}

/********************************
 *
 *  应用构建前调用此函数
 *
 *  注意：用户可添加代码
 *
 ********************************/
void HmiApp::onInit(){
	//用户在此添加客户化代码
}

/********************************
 *
 *  应用构建函数
 *
 *  注意：IDE自动生成，用户勿修改
 *
 ********************************/
void HmiApp::construct() {
	//注册字体文件
	fm->registerFontFile("文泉驿微米黑", "./fnt/wenquanyiweimihei.ttf");
	//设备注册
	dm->addDevice("Modbus/RTU_按分区", R"({"stopBits":"1","maxReadLen":"120","parity":"0","DeviceId":"Modbus/RTU_按分区","portName":"COM9","maxAddrInterval":"5","issim":"true","NoR":"3","coding":"0","seqAsc":"0","comDelay":"1200","StationNo":"1","seqLong":"0","Protocol":"ModbusRtu","if":"RS485","framDelay":"4","seqFloat":"2","period":"100","Optz":"true","dll":"ModBusDriver","seqInt32":"2","dataSize":"8","maxWriteLen":"120","baudRate":"9600","seqInt16":"0"})");
	dm->addDevice("Modbus/RTU_按分区", R"({"stopBits":"1","maxReadLen":"120","parity":"0","DeviceId":"Modbus/RTU_按分区","portName":"COM2","maxAddrInterval":"5","issim":"false","NoR":"3","coding":"0","seqAsc":"0","comDelay":"1200","StationNo":"1","seqLong":"0","Protocol":"ModbusRtu","if":"RS485","framDelay":"4","seqFloat":"2","period":"100","Optz":"true","dll":"ModBusDriver","seqInt32":"2","dataSize":"8","maxWriteLen":"120","baudRate":"9600","seqInt16":"0"})");
	dm->addDevice("语音合成", R"({"issim":"true","p":"50","r":"2","rpc":"dll","dll":"IoDriver","v":"50","DeviceId":"语音合成","vn":"xiaofeng","Protocol":"TTS","if":"dll","sr":"16000"})");
	dm->addDevice("语音合成", R"({"issim":"false","p":"50","r":"2","rpc":"dll","dll":"IoDriver","v":"50","DeviceId":"语音合成","vn":"xiaofeng","Protocol":"TTS","if":"dll","sr":"16000"})");
	//设备变量
	vm->add("tts_speed", DataType::D_INT, R"({"dvc":"语音合成","a":"0","c":"s","t":"0","id":"v4","l":"0"})");
	vm->add("tts_volume", DataType::D_INT, R"({"dvc":"语音合成","a":"0","c":"sv","t":"0","id":"v5","l":"0"})");
	vm->add("tts_playcnt", DataType::D_INT, R"({"dvc":"语音合成","a":"0","c":"sc","t":"0","id":"v6","l":"0"})");
	vm->add("tts_text", DataType::D_VCHAR, R"({"dvc":"语音合成","a":"0","c":"cc","t":"0","id":"v7","l":"64"})");
	vm->add("温度", DataType::D_INT16, R"({"dvc":"Modbus/RTU_按分区","a":"0","c":"[4区]输出寄存器","t":"0","id":"v8","l":"0"})");
	vm->add("湿度", DataType::D_INT16, R"({"dvc":"Modbus/RTU_按分区","a":"1","c":"[4区]输出寄存器","t":"0","id":"v9","l":"0"})");
	//常规变量
	vm->add("变量_1", DataType::T_FLOAT, R"({"i":"59.8","id":"v1"})");
	vm->add("test11", DataType::T_INT, R"({"id":"v10"})");
	vm->add("test22", DataType::T_INT, R"({"id":"v11"})");
	vm->add("温度补偿", DataType::T_INT, R"({"id":"v16"})");
	vm->add("湿度补偿", DataType::T_INT, R"({"id":"v17"})");
	vm->add("test33", DataType::T_INT, R"({"id":"v18"})");
	vm->add("test44", DataType::T_INT, R"({"id":"v19"})");
	vm->add("test55", DataType::T_INT, R"({"id":"v20"})");
	vm->add("test66", DataType::T_INT, R"({"id":"v21"})");
	vm->add("test77", DataType::T_LONG, R"({"id":"v22"})");
	vm->add("倒计时_秒", DataType::T_INT, R"({"id":"v23"})");
	//资料采样设置
	stt::op::SampleMgr::getInstance(rt)->load(5);
	//背光、屏保
	pm->setBackLightHoldingTime(0, 50);
}

IPagePtr HmiApp::buildPage(string id, uint8_t mode, STTWidget *target) {
	if (id == "Frm02")
		return new Frm02(this, target, "Frm02", "Frm02");
	if (id == "Frm03")
		return new Frm03(this, target, "Frm03", "Frm03");
	if (id == "Frm04")
		return new Frm04(this, target, "Frm04", "Frm04");
	if (id == "Frm05")
		return new Frm05(this, target, "Frm05", "Frm05");
	if (id == "Frm06")
		return new Frm06(this, target, "Frm06", "Frm06");
	if (id == "Frm07")
		return new Frm07(this, target, "Frm07", "Frm07");
	if (id == "Frm08")
		return new Frm08(this, target, "Frm08", "Frm08");
	if (id == "Frm09")
		return new Frm09(this, target, "Frm09", "Frm09");
	if (id == "Frm10")
		return new Frm10(this, target, "Frm10", "Frm10");
	return new Frm01(this, target, "Frm01", "Frm01");
}

/********************************
 *
 *  构建应用后调用此函数
 *
 *  注意：用户可添加代码
 *
 ********************************/
void HmiApp::onReady(){
	//用户在此添加客户化代码
}

/********************************
 *
 *  应用退出前调用此函数
 *
 *  注意：用户可添加代码
 *
 ********************************/
void HmiApp::onQuit(){
	//用户在此添加客户化代码
}

#endif /* STT_HMIAPP_CPP_ */


